import type { App } from 'vue';
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';

// import system from './modules/system.ts';
import pages from './modules/pages.ts';

export const publicRoutes: Array<RouteRecordRaw> = [
	{
        path: '/login',
        name: 'login',
        component: () => import('@/views/system/login/login.vue'),
        meta: {
            title: '登录页'
        }
    }, {
        path: '/',
        component: () => import('@/layout/index.vue'),
        name: 'layout',
        children: [
            {
                path: '/',
                name: 'index',
                component: () => import('@/views/system/index/index.vue'),
                meta: {
                    title: '首页'
                }
            },
			...pages
        ]
    },
];

const router = createRouter({
	history: createWebHashHistory(),
	routes: publicRoutes
});

/* 初始化路由表 */
export function resetRouter() {
	router.getRoutes().forEach((route) => {
		const { name } = route;
		if (name) {
			router.hasRoute(name) && router.removeRoute(name);
		}
	});
}
/* 导出 setupRouter */
export const setupRouter = (app: App<Element>) => {
	app.use(router);
};